$(function (){
	var data = clothingType;
	$("#clothTypeDatagrid").datagrid({
		data:{"rows":clothingType},
	    fit:true,
	    toolbar:'#clothTypeTolbar',
	    fitColumns:true,
	    rownumbers:true,
	    singleSelect:true,
	    columns:[[  
	        {field:'id',title:'类型编号',width:100,align:"center"},
	        {field:'text',title:'类型名称',width:100,align:"center"}, 
	        {field:'operation',title:'操作',width:100,align:"center",
	        	formatter:function(value,row,index){
	        		return " <a  href='#' onclick=editRow("+index+");  >编辑</a> "+
	                  " <a  href='#' onclick=deleteRow('"+row.clothingId+"'); >删除</a> ";
	        	}
	        	
	        },
	    ]]  
	
	});
	
	$("#addDialog").dialog({
		title: '新增服装类型',  
	    width: 310,  
	    height:330,  
	    closed: true,  
	    cache: false,    
	    modal: true ,
	    buttons:[{
			text:'保存',
			handler:function(){
				var arr = {
						"id":$("#addclothingTypeId").val(),
						"text":$("#addclothingTypeName").val()
				}
				clothingType.push(arr);
				$("#clothTypeDatagrid").datagrid("loadData",{"rows":clothingType});
			}
		},{
			text:'关闭',
			handler:function(){
				$("#addDialog").dialog("close");
			}
		}]
	});
	
	$("#editDialog").dialog({
		title: '编辑服装类型',  
	    width: 310,  
	    height:330,  
	    closed: true,  
	    modal: true ,
	    buttons:[{
			text:'保存',
			handler:function(){
				
			
			}
		},{
			text:'关闭',
			handler:function(){
				$("#editDialog").dialog("close");
			}
		}]
	})
	
})

function doAdd(){
	$("#addDialog").dialog("center");
	$("#addDialog").dialog("open");
	$("#addDialogForm").form("clear");
}

function editRow(index){
	$("#editDialog").dialog("center");
	$("#editDialog").dialog("open");

	$('#clothTypeDatagrid').datagrid("selectRow",index);
	var row = $('#clothTypeDatagrid').datagrid("getSelected");
	if(!row){
		$('#clothTypeDatagrid').datagrid("selectRow",index);
		row = $('#clothTypeDatagrid').datagrid("getSelected");
	}
	
}

function deleteRow(id){
	 $.messager.confirm("操作提示", "您确定要删除吗？", function (data) {  
        if (data) {  
			
        } else {  
            return;  
         }  
     }); 
}